/*
 * @Description: robot grpc server
 * @Version: V1.0
 * @Author: zw_1520@163.com
 * @Date: 2024-09-09 13:55:48
 * @LastEditors: zw_1520@163.com
 * @LastEditTime: 2025-04-21 15:50:52
 * Copyright (C) All rights reserved.
 */
#ifndef __ROBOT_GRPC_SERVER_H__
#define __ROBOT_GRPC_SERVER_H__

#include <grpcpp/ext/proto_server_reflection_plugin.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>

#include <iostream>
#include <memory>
#include <queue>
#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>
#include <string>

#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/strings/str_format.h"
#include "robot_grpc_proto/robot.grpc.pb.h"
#include "stream_data_reactor.h"

using grpc::CallbackServerContext;
using grpc::Server;
using grpc::ServerBidiReactor;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using robot::RobotController;
using robot::RobotRequest;
using robot::RobotResponse;

class RobotGrpcServer : public rclcpp::Node {
 public:
  RobotGrpcServer();

  // Starts grpc server
  void StartGrpcServer();

  // Defines ros2 topic callback for server message topic
  void serverMessageCallback(const std_msgs::msg::String::SharedPtr msg);

 private:
  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr m_server_message_sub_;
  RobotControllerServiceImpl* robot_grpc_service_;
};

#endif